package com.imooc.config;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.net.InetAddress;
import java.net.UnknownHostException;

@Configuration
public class ESConfig {

    @Value("${spring.data.elasticsearch.cluster-nodes}")
    String esHost;

    @PostConstruct
    void init() throws UnknownHostException {
        System.setProperty("es.set.netty.runtime.available.processors", "false");
        // 关闭网络嗅探
       /* Settings settings = Settings.builder().put("cluster.name","zdp-elasticsearch").
                put("client.transport.sniff",false).build();
        TransportClient client = new PreBuiltTransportClient(settings);
        System.out.println(esHost);
        client.addTransportAddress(new TransportAddress(InetAddress.getByName("101.37.247.31"),9300));*/
    }
}
